package com.shangdiao.sd_server.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.shangdiao.sd_server.pojo.Row;
/**
 * @author btshen
 * 
 */
public class FastjsonUtil {
    public static SerializeConfig mapping = new SerializeConfig();

    static {
        mapping.put(Date.class, new SimpleDateFormatSerializer(DateUtil.FORMAT_ONE));
    }

    public static <T> T parseObject(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }

    public static <T> List<T> parseArray(String json, Class<T> clazz) {
        return JSON.parseArray(json, clazz);
    }

    public static String toJSONString(Object target) {
        return JSON.toJSONString(target, mapping);
    }

    public static Row parseObjectToRow(Object target) {
        return parseObject(toJSONString(target), Row.class);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        List<Row> list = new ArrayList<Row>();
        Row r = new Row();
        r.put("hello", "1");
        r.put("hello2", "2");
        list.add(r);

        List list1 = new ArrayList();
        list1.add(list);

        System.out.println(toJSONString(list1));
    }

}
